package br.com.colegio.dao.storage;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

import br.com.colegio.dao.CanalPagamentoDAO;
import br.com.colegio.util.SpecialCharFilter;
import br.com.colegio.vo.CanalPagamento;

public class CanalPagamentoData
{
	private static CanalPagamentoData instance;
	private Map<Integer, CanalPagamento> data = new HashMap<Integer, CanalPagamento>(); 

	private CanalPagamentoData()
	{
	}

	public static CanalPagamentoData getInstance()
	{
		if (instance == null)
			instance = new CanalPagamentoData();

		return instance;
	}

	private Map<Integer, CanalPagamento> getData()
	{
		if (data.size() == 0)
		{
			Collection<Object> r = CanalPagamentoDAO.list();

			if (r != null)
				for (Object o : r)
				{
					CanalPagamento c = (CanalPagamento)o;
					data.put(c.getCodigo(), c);
				}
		}

		return data;
	}

	public Collection<CanalPagamento> listar()
	{
		Map<String, CanalPagamento> ma = new TreeMap<String, CanalPagamento>();

		for (Integer k : getData().keySet())
			ma.put(SpecialCharFilter.replaceSpecial(getData().get(k).getDescricao().toUpperCase()), getData().get(k));

		return ma.values();
	}

	public CanalPagamento getCanalPagamento(int cod)
	{
		return getData().get(cod);
	}
}